package com.bwie.parkdemo.mvvm.model.entity;

import android.text.TextUtils;

import com.bwie.lib_core.base.BaseEntity;
import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;

import java.util.ArrayList;
import java.util.List;

/**
 * 历史签到实体类
 * {
 "msg": "成功",
 "values": "[{\"endAddress\":\"签退经纬度\",
 \"endTime\":1584028800000,\"signId\":94,
 \"startAddress\":\"签到经纬度\",
 \"startTime\":1584028800000,\"userId\":0}]",
 "statuesCode": "200"
 }
 * */
public class HistorySignEntity extends BaseEntity{

    private String values;
    private List<Object>datas;

    public void setValues(String values) {
        this.values = values;
    }

    public List<Object> getDatas() {
        datas = new ArrayList<>();
        if (TextUtils.isEmpty(values))
            return datas;
        try {
            JSONArray jsonArray = new JSONArray(values);
            for (int i = 0;i < jsonArray.length();i ++){
                String jsonStr = jsonArray.getJSONObject(i).toString();
                Values entity = new Gson().fromJson(jsonStr,Values.class);
                datas.add(entity);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        //添加表头
        Values entity = new Values();
        entity.flag = true;
        datas.add(0,entity);
        return datas;
    }

    public static class Values{
        public int userId;
        public int signId;
        public String startTime;
        public String endTime;
        public String startAddress;
        public String endAddress;
        public boolean flag = false;

    }

}
